package com.example.shirospringboot.controller.orderController;

import com.example.shirospringboot.pojo.Order;
import com.example.shirospringboot.service.OrderService.orderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class orderController {

    @Autowired
    orderServiceImpl orderService;

    @RequestMapping("/listOrder")
    public String queryAllOrder(Model model){
        List<Order> orders = orderService.queryAllOrder();
        model.addAttribute("orders",orders);
        return "emp/order";
    }

    @RequestMapping("/listUnAuthorOrder")
    public String queryOrderByAuthority(Model model){
        List<Order> orders = orderService.queryOrderByAuthority();
        model.addAttribute("orders",orders);
        return "emp/unAuthorOrder";
    }

    @RequestMapping("/toAuthor/{id}")
    public String toAuthor(@PathVariable("id") int id){

        orderService.toAuthor(id);
        return "redirect:/listUnAuthorOrder";
    }

    @RequestMapping("/toDeny/{id}")
    public String toDeny(@PathVariable("id") int id){

        orderService.toDeny(id);
        return "redirect:/listUnAuthorOrder";
    }
}
